﻿using System.Net.Sockets;
using Thrift.Transport;

namespace SKBKontur.Cassandra.Proxy
{
    public class ProxyFactory: IProxyFactory
    {
        private readonly string host;
        private readonly int port;

        public ProxyFactory(string host, int port)
        {
            this.host = host;
            this.port = port;
        }

        #region IProxyFactory Members

        public IStorage CreateStorage(string keySpace)
        {
            var socket = new TcpClient(host, port) {NoDelay = true};
            var transport = new TFramedTransport(new TSocket(socket));
            return new Storage(transport, keySpace);
        }

        public IConfigurator CreateConfigurator()
        {
            var transport = new TFramedTransport(new TSocket(host, port));
            transport.Open();
            return new Configurator(transport);
        }

        #endregion
    }
}